import React, { useEffect, useState } from 'react';
import FormRender, { useForm } from 'form-render';
import { getFormTemplateById } from '@/services/formTemplateService'
import { useParams } from 'react-router';

export default () => {
  debugger
  const form = useForm();
  const params = useParams<{ id: string }>();
  const [schema, setSchema] = useState<any>();

  const getFormById = async () => {
    const { Items } = await getFormTemplateById(parseInt(params.id));
    setSchema(JSON.parse(Items[0].SchemaJson));
  }

  useEffect(() => {
    getFormById();
  }, [])

  return (
    <FormRender
      form={form}
      schema={schema}
    />
  );
}
